import crdc, logging, argparse
argp = argparse.ArgumentParser(description='Flat file formatter for the Civil Rights Data Collection')
argp.add_argument('options_file', help='Full file path to the options.ini')
argp.add_argument('--skip_school1', default=False, action='store_const', const=True, help='Skip part school 1')
argp.add_argument('--skip_school2', default=False, action='store_const', const=True, help='Skip part school 2')
argp.add_argument('--skip_load', default=False, action='store_const', const=True, help='Do not (re)load the data file into the internal database, overwriting existing contents')
argp.add_argument('--verbosity', default='info', choices=['warning','info','debug'], help='Display messages with this urgency level or lower')
verbose_levels = dict({'warning': logging.WARNING,
						'info': logging.INFO,
						'debug': logging.DEBUG})
args = argp.parse_args()
crdc = crdc.crdc(args.options_file)
crdc.logger.setLevel(verbose_levels[args.verbosity])
crdc.logger.debug('options-file={}'.format(args.options_file))
parts = ['school1','school2']
if args.skip_school1:
	parts.remove('school1')
if args.skip_school2:
	parts.remove('school2')
if len(parts) == 0:
	raise Exception('You must call for school1, or school2, or both.')
crdc.parts = parts
crdc.logger.debug('Parts are {}'.format(parts))
crdc.schools_load()
crdc.element_config_load()
if not args.skip_load:
	crdc.detail_load()
crdc.final_values_build()
crdc.report()
crdc.logger.info('All done. Files are in {}'.format(crdc.configs['data_dir']))
